package me.zhanshi123.pixelpaygui

import io.izzel.taboolib.module.config.TConfig
import io.izzel.taboolib.module.inject.TFunction
import io.izzel.taboolib.module.inject.TInject
import me.zhanshi123.pixelpaygui.gui.open.OpenGuiHolder
import me.zhanshi123.pixelpaygui.gui.paymoney.PayGuiHolder
import org.bukkit.Bukkit

object ConfigManager {

    @TInject
    lateinit var config: TConfig
        private set

    @TFunction.Init
    fun init() {
        config!!.listener {
            Bukkit.getOnlinePlayers()
                    .filter { it.openInventory != null }
                    .filter { it.openInventory.topInventory != null }
                    .filter { it.openInventory.topInventory.holder is PayGuiHolder || it.openInventory.topInventory.holder is OpenGuiHolder }
                    .forEach { it.closeInventory() }
            Main.instance.initInventory()
            Main.instance.logger.info("配置文件重载完成")
        }
    }
}